#include "clocker.h"
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <chrono>

#define log(...) do {                \
            printf(__VA_ARGS__);     \
            printf("\n");            \
        } while(0);

struct clocker_object
{
    int num;
    std::chrono::high_resolution_clock::time_point begin;
    std::chrono::high_resolution_clock::time_point end;
	double duration;
};

static struct clocker_object clk_obj;
static int device_carry_out_numbering = 0;

int clocker_begin()
{
    struct clocker_object *clk = &clk_obj;
    memset(clk, 0, sizeof(struct clocker_object));
    clk->num = device_carry_out_numbering++;
    clk->begin = std::chrono::high_resolution_clock::now();
    log("----------------- clocker : num:[%d] start -----------------", clk->num);
    return clk->num;
}

double clocker_end()
{
    struct clocker_object *clk = &clk_obj;
    clk->end = std::chrono::high_resolution_clock::now();
    clk->duration = std::chrono::duration_cast<std::chrono::milliseconds>(clk->end - clk->begin).count();
    log("----------------- clocker : num:[%d] end   -----------------", clk->num);
    log("> clocker : num [%d] run time [%.3f] ms ...", clk->num, clk->duration);
    return clk->duration;
}
